<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\JsonRpc;

use App\Repository\ArticleRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\ArticleServiceInterface;

/**
 * @RpcService(name="Config::ArticleService", protocol="jsonrpc", server="jsonrpc")
 */
class ArticleService extends BaseService implements ArticleServiceInterface
{
    public function init()
    {
        $this->repository = ArticleRepository::getInstance();
    }

    public function index(array $condition, array $field, int $page, int $size): array
    {
        if(isset($condition['title']) && !empty($condition['title'])){
            $condition[] = ['title', 'like', '%'.trim($condition['title']).'%'];
            unset($condition['title']);
        }
        return parent::index($condition, $field, $page, $size);
    }
}
